package alingrad.engine.collisions;

public class CollisionMask {
	private float mX;
	private float mY;
	private CollisionMaskData mData;

	public float mLeft;
	public float mRight;
	public float mTop;
	public float mBottom;

	public CollisionMask() {
	}

	public CollisionMask update(final CollisionMaskData data, final float x, final float y) {
		mX = x;
		mY = y;
		if (data != null) {
			mData = data;
		}
		updateBoundingBox();
		return this;
	}

	private void updateBoundingBox() {
		mLeft = mX + mData.mLeft;
		mRight = mLeft + mData.mWidth - 1;
		mBottom = mY + mData.mBottom;
		mTop = mBottom + mData.mHeight - 1;
	}

	public boolean checkBoundingBoxCollision(final float x, final float y) {
		if (x < mLeft)
			return false;
		if (y < mBottom)
			return false;
		if (x > mRight)
			return false;
		if (y > mTop)
			return false;
		return true;
	}

	public boolean checkBoundingBoxCollision(final CollisionMask other) {
		if (mRight < other.mLeft)
			return false;
		if (mTop < other.mBottom)
			return false;
		if (mLeft > other.mRight)
			return false;
		if (mBottom > other.mTop)
			return false;
		return true;
	}

	public boolean checkCollision(final float x, final float y) {
		if (checkBoundingBoxCollision(x, y))
			return true;
		return false;
	}

	public boolean checkCollision(final CollisionMask other) {
		if (checkBoundingBoxCollision(other))
			return true;
		return false;
	}
}
